/*
 * @lc app=leetcode.cn id=232 lang=cpp
 *
 * [232] 用栈实现队列
 */
#include "include.h"
// @lc code=start
class MyQueue {
public:
    stack<int> stack_;
    MyQueue() {
        
    }
    
    void push(int x) {
        stack_.push(x);
    }
    
    int pop() {
        stack<int> stackReverse;
        int temp;
        while (!stack_.empty()){
            temp = stack_.top();
            stackReverse.push(temp);
            stack_.pop();
        }
        int res = temp;

        stackReverse.pop();

        while (!stackReverse.empty()){
            temp = stackReverse.top();
            stack_.push(temp);
            stackReverse.pop();
        }
        return res;
    }
    
    int peek() {
        stack<int> stackReverse;
        int temp;
        while (!stack_.empty()){
            temp = stack_.top();
            stackReverse.push(temp);
            stack_.pop();
        }
        int res = temp;
        while (!stackReverse.empty()){
            temp = stackReverse.top();
            stack_.push(temp);
            stackReverse.pop();
        }
        return res;
    }
    
    bool empty() {
        return stack_.empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
// @lc code=end

